package com.hfy.shop.mapper;

import com.hfy.model.po.order.OrderPo;
import com.hfy.model.vo.PopOrderVo;
import com.hfy.model.vo.order.WholeOrderVo;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @ author 韩
 * time: 2024/9/10 16:23
 */

@Mapper
public interface OrderMapper {
    @Insert("INSERT INTO `order` (id, good_id, start_time, end_time, duration, account) VALUES (#{orderId}, #{goodId}, #{startTime}, #{endTime}, #{duration}, #{account})")
    @Options(useGeneratedKeys = true, keyProperty = "orderId")
    void creatOrder(PopOrderVo vo);

    @Select("SELECT id, good_id goodId, start_Time startTime, end_time endTime, duration, account, cancel_time cancelTime, status " +
            "FROM `order` WHERE id = #{orderId}")
    OrderPo getOrderInfo(@Param("orderId") Integer orderId);

    @Update("UPDATE `order` SET cancel_time = #{cancelTime}, status = #{status} WHERE id=#{orderId}")
    void finishOrder(@Param("orderId") Integer orderId, @Param("cancelTime") LocalDateTime cancelTime, @Param("status") Integer status);

    // 淘宝是按下单时间排的序

//    @Select("SELECT id, good_id goodId, start_Time startTime, end_time endTime, duration, account, cancel_time cancelTime, status " +
//            "FROM `order`" +
//            "<if test='status!= null'> WHERE status = #{status} </if>")
    List<WholeOrderVo> getOrderListByStatus(@Param("status") String status, @Param("account") Long account);

}
